/*     */ package com.zimbra.cs.mailbox.alerts;
/*     */ 
/*     */ import com.zimbra.common.calendar.ParsedDateTime;
/*     */ import com.zimbra.common.calendar.ParsedDuration;
/*     */ import com.zimbra.common.mime.shim.JavaMailInternetAddress;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.L10nUtil;
/*     */ import com.zimbra.common.util.L10nUtil.MsgKey;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.mailbox.CalendarItem;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.MailSender;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.calendar.Invite;
/*     */ import com.zimbra.cs.mailbox.calendar.Util;
/*     */ import com.zimbra.cs.mailbox.calendar.ZOrganizer;
/*     */ import com.zimbra.cs.mime.Mime.FixedMimeMessage;
/*     */ import com.zimbra.cs.util.JMSession;
/*     */ import java.text.DateFormat;
/*     */ import java.util.Date;
/*     */ import java.util.Locale;
/*     */ import java.util.TimeZone;
/*     */ import javax.mail.Message.RecipientType;
/*     */ import javax.mail.internet.MimeMessage;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CalItemSmsReminderTask
/*     */   extends CalItemReminderTaskBase
/*     */ {
/*     */   static final String TASK_NAME_PREFIX = "smsReminderTask";
/*     */   
/*     */   public String getName()
/*     */   {
/*  52 */     return "smsReminderTask" + getProperty("calItemId");
/*     */   }
/*     */   
/*     */   protected void sendReminder(CalendarItem calItem, Invite invite) throws Exception
/*     */   {
/*  57 */     Account account = calItem.getAccount();
/*  58 */     Locale locale = account.getLocale();
/*  59 */     TimeZone tz = Util.getAccountTimeZone(account);
/*  60 */     MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSmtpSession(account));
/*  61 */     String to = account.getAttr("zimbraCalendarReminderDeviceEmail");
/*  62 */     if (to == null) {
/*  63 */       ZimbraLog.scheduler.info("Unable to send calendar reminder sms since %s is not set", new Object[] { "zimbraCalendarReminderDeviceEmail" });
/*  64 */       return;
/*     */     }
/*  66 */     mm.setRecipient(Message.RecipientType.TO, new JavaMailInternetAddress(to));
/*  67 */     mm.setText(getText(calItem, invite, locale, tz), "utf-8");
/*  68 */     mm.saveChanges();
/*  69 */     MailSender mailSender = calItem.getMailbox().getMailSender();
/*  70 */     mailSender.setSaveToSent(false);
/*  71 */     mailSender.sendMimeMessage(null, calItem.getMailbox(), mm);
/*     */   }
/*     */   
/*     */   private String getText(CalendarItem calItem, Invite invite, Locale locale, TimeZone tz) throws ServiceException {
/*  75 */     DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(3, 3, locale);
/*  76 */     dateTimeFormat.setTimeZone(tz);
/*  77 */     DateFormat onlyDateFormat = DateFormat.getDateInstance(3, locale);
/*  78 */     onlyDateFormat.setTimeZone(tz);
/*     */     String formattedEnd;
/*     */     String formattedStart;
/*     */     String formattedEnd;
/*  82 */     if (calItem.getType() == MailItem.Type.APPOINTMENT) {
/*  83 */       Date start = new Date(new Long(getProperty("nextInstStart")).longValue());
/*  84 */       String formattedStart = dateTimeFormat.format(start);
/*  85 */       Date end = invite.getEffectiveDuration().addToDate(start);
/*  86 */       formattedEnd = dateTimeFormat.format(end);
/*     */     }
/*     */     else {
/*  89 */       formattedStart = invite.getStartTime() == null ? "" : onlyDateFormat.format(invite.getStartTime().getDate());
/*  90 */       formattedEnd = invite.getEndTime() == null ? "" : onlyDateFormat.format(invite.getEndTime().getDate());
/*     */     }
/*     */     
/*  93 */     String location = invite.getLocation();
/*  94 */     if (StringUtil.isNullOrEmpty(location)) {
/*  95 */       location = L10nUtil.getMessage(L10nUtil.MsgKey.noLocation, new Object[0]);
/*     */     }
/*  97 */     String organizer = null;
/*  98 */     ZOrganizer zOrganizer = invite.getOrganizer();
/*  99 */     if (zOrganizer != null)
/* 100 */       organizer = zOrganizer.hasCn() ? zOrganizer.getCn() : zOrganizer.getAddress();
/* 101 */     if (organizer == null) { organizer = "";
/*     */     }
/* 103 */     String folder = calItem.getMailbox().getFolderById(null, calItem.getFolderId()).getName();
/*     */     
/* 105 */     return L10nUtil.getMessage(calItem.getType() == MailItem.Type.APPOINTMENT ? L10nUtil.MsgKey.apptReminderSmsText : L10nUtil.MsgKey.taskReminderSmsText, locale, new Object[] { calItem.getSubject(), formattedStart, formattedEnd, location, organizer, folder });
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/alerts/CalItemSmsReminderTask.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */